﻿@{
    ViewBag.Title = "SectionSalaryList";
    Layout = "~/Views/Shared/_UserPage.cshtml";
}

<script type="text/javascript">
    $(function () {
        $("#ProjectID").combobox({
            editable: false, panelHeight: "auto",
            valueField: 'ID',
            textField: 'ProjectName',
            url: '/ProjectInfo/ProjectInfoListForFlow',
            onLoadSuccess: function () {
                var data = $("#ProjectID").combobox('getData');
                if (data.length > 0) {
                    $("#ProjectID").combobox('select', data[0]["ID"]);
                }
            }
        });

        $('#ContractType').combobox({
            editable: false, panelHeight: "auto",
            valueField: "DictionaryName",
            textField: "DictionaryName",
            url: "/Dictionary/GetDictionaryByTypeTag?typeTag=ContractType",
            onLoadSuccess: function () {
                var data = $('#ContractType').combobox('getData');
                if (data.length > 0) {
                    $('#ContractType').combobox('select', data[0]["DictionaryName"]);
                }
            }
        });

        $("#Year").combobox({
            editable: false, panelHeight: "auto",
            valueField: "DictionaryName",
            textField: "DictionaryName",
            url: "/Dictionary/GetDictionaryByTypeTag?typeTag=Year",
            onLoadSuccess: function () {
                var data = $('#Year').combobox('getData');
                if (data.length > 0) {
                    $('#Year').combobox('select', data[0]["DictionaryName"]);
                }
            }
        });
    });

    function Search() {
        initDetailTable('', '');
        initDocument('', '');
        document.getElementById("divRemark").style.display = "block";
        initTable();
    }

    function initTable() {
        var projectID = $("#ProjectID").combobox('getValue');
        var contractType = $("#ContractType").combobox('getValue');
        var year = $("#Year").combobox('getValue');

        $('#summaryDataGrid').datagrid({
            url: '/SectionSalary/GetSectionSalaryList?projectID=' + projectID + '&contractType=' + encodeURI(contractType) + '&year=' + year,
            iconCls: 'icon-bricks',
            nowrap: true,//当数据长度超出列宽时将会自动截取
            autoRowHeight: false,
            striped: true,//设置为true将交替显示行背景
            collapsible: true,
            remoteSort: false,
            singleSelect: true,
            fitColumns: true,
            toolbar: '#summaryToolBar',
            columns:
            [[
                { title: 'ContractID', field: 'ContractID', hidden: true },
                { title: '标段名称', field: 'ContractName', align: 'center', width: 50 },
                { title: '1月', field: 'JanuarySalary', align: 'center', width: 40 },
                { title: '2月', field: 'FebruarySalary', align: 'center', width: 40 },
                { title: '3月', field: 'MarchSalary', align: 'center', width: 40 },
                { title: '4月', field: 'AprilSalary', align: 'center', width: 40 },
                { title: '5月', field: 'MaySalary', align: 'center', width: 40 },
                { title: '6月', field: 'JuneSalary', align: 'center', width: 40 },
                { title: '7月', field: 'JulySalary', align: 'center', width: 40 },
                { title: '8月', field: 'AugustSalary', align: 'center', width: 40 },
                { title: '9月', field: 'SeptemberSalary', align: 'center', width: 40 },
                { title: '10月', field: 'OctoberSalary', align: 'center', width: 40 },
                { title: '11月', field: 'NovemberSalary', align: 'center', width: 40 },
                { title: '12月', field: 'DecemberSalary', align: 'center', width: 40 },
            ]],
            onDblClickCell:
                function (index, field, value) {
                    var selected = $('#summaryDataGrid').datagrid('getSelected');
                    if (selected != null) {
                        var month;
                        switch (field) {
                            case "JanuarySalary":
                                month = '1';
                                break;
                            case "FebruarySalary":
                                month = '2';
                                break;
                            case "MarchSalary":
                                month = '3';
                                break;
                            case "AprilSalary":
                                month = '4';
                                break;
                            case "MaySalary":
                                month = '5';
                                break;
                            case "JuneSalary":
                                month = '6';
                                break;
                            case "JulySalary":
                                month = '7';
                                break;
                            case "AugustSalary":
                                month = '8';
                                break;
                            case "SeptemberSalary":
                                month = '9';
                                break;
                            case "OctoberSalary":
                                month = '10';
                                break;
                            case "NovemberSalary":
                                month = '11';
                                break;
                            case "DecemberSalary":
                                month = '12';
                                break;
                        }
                        $("#hUserType").val(month);
                        initDetailTable(selected.ContractID, month);

                        var projectID = $("#ProjectID").combobox('getValue');
                        var contractType = $("#ContractType").combobox('getValue');
                        var year = $("#Year").combobox('getValue');
                        $.post('/SectionSalary/GetSectionSalaryID?projectID=' + projectID + '&contractType=' + encodeURI(contractType) + '&contractID=' + selected.ContractID + '&year=' + year + '&month=' + month, function (res) {
                            var tag = "WorkerManagement/SectionSalaryList/Attachment";
                            initDocument(res, tag);
                        });
                    }
                }
        });
    }

    function initDetailTable(contractID, month) {
        var projectID = $("#ProjectID").combobox('getValue');
        var contractType = $("#ContractType").combobox('getValue');
        var year = $("#Year").combobox('getValue');

        $('#detailDataGrid').datagrid({
            url: '/SectionSalary/GetSectionSalaryDetailList?projectID=' + projectID + '&contractType=' + encodeURI(contractType) + '&contractID=' + contractID + '&year=' + year + '&month=' + month,
            iconCls: 'icon-bricks',
            nowrap: true,//当数据长度超出列宽时将会自动截取
            autoRowHeight: false,
            striped: true,//设置为true将交替显示行背景
            collapsible: true,
            remoteSort: false,
            idField: 'ID',//表明该列是一个唯一列。
            singleSelect: true,
            fitColumns: true,
            columns:
            [[
                { title: '身份证', field: 'CertificateNo', align: 'center', width: 100 },
                { title: '姓名', field: 'Name', align: 'center', width: 100 },
                { title: '性别', field: 'Sex', align: 'center', width: 50 },
                { title: '年龄', field: 'Age', align: 'center', width: 50 },
                { title: '工种', field: 'WorkType', align: 'center', width: 200 },
                { title: '累计工资发放', field: 'MonthSalary', align: 'center', width: 100 },
                { title: '身份证附件', field: 'IDCAttachment', align: 'center', width: 150 },
                { title: '合同附件', field: 'ContractAttachment', align: 'center', width: 150 }
            ]]
        });
    }

    function initDocument(instanceID, tag) {
        $('#documentGrid').datagrid({
            //url: '/Document/GetDocumentList?instanceID=681764fd-aef8-4dcf-84bd-a2d700ffc9a0&Tag=Test',  //开发期测试
            url: '/Document/GetDocumentList?instanceID=' + instanceID + '&Tag=' + tag,  //运行期使用
            nowrap: true,
            autoRowHeight: true,
            striped: true,
            collapsible: true,
            rownumbers: true,
            remoteSort: false,
            idField: 'ID',
            singleSelect: true,
            //queryParams: queryData,
            columns: [[
                {
                    title: '文件名', field: 'FileName', width: 220,
                    formatter: function (value, row, index) {
                        return '<a href="' + row["FilePath"] + '">' + value + '</a> ';
                    }
                },
                { title: '文件大小', field: 'FileSize', width: 70, sortable: true },
                { field: 'UploadUserID', hidden: true },
                { title: '上传人', field: 'UploadUser', width: 80, sortable: true },
                { title: '上传时间', field: 'UploadTime', width: 100, sortable: true }

            ]],
            toolbar: '#documentToolBar'
        });
    }

    var SectionSalaryList =
    {
        Add: function () {
            var projectID = $("#ProjectID").combobox('getValue');
            var contractType = $("#ContractType").combobox('getValue');
            var year = $("#Year").combobox('getValue');
            if (projectID == '' || contractType == '' || year == '') {
                $.messager.alert('操作提示', "项目、合同类型和年份不能为空！", 'info');
            }
            else {
                $.post("/UserMenuAction/GetUserDepartmentForFlow?menuCode=SectionSalaryList", function (userDepartment) {
                    if (userDepartment == "") {
                        showMyWindow("#myWindow", "选择机构", "/UserMenuAction/ShowOrgByUserForFlow?menuCode=SectionSalaryList", 500, 280, true, false);
                    }
                    else if (userDepartment == "**********") {
                        $.messager.alert('操作提示', '当前用户不属于任何机构，请先设置所属机构！', 'info');
                    }
                    else if (userDepartment == "++++++++++") {
                        $.messager.alert('操作提示', '当前用户的机构不属于流程申请配置机构，不能新增！', 'info');
                    }
                    else {
                        showMyWindow("#myWindow", "", '/SectionSalary/SectionSalary?MenuCode=SectionSalary&sourceType=1&processType=&sourceID=&lastUpdateUserDepartment=' + userDepartment + '&projectID=' + projectID + '&contractType=' + encodeURI(contractType) + '&year=' + year, 1000, 500, true, true, true);
                    }
                });
            }
        },

        Delete: function () {
            var row = $("#yearPlanGrid").datagrid("getSelected");
            var projectID = $("#ProjectID").combobox('getValue');
            var contractType = $("#ContractType").combobox('getValue');
            var year = $("#Year").combobox('getValue');
            var month = $("#hUserType").val();
            if (month == '') {
                $.messager.alert('操作提示', "请点击某一个单元格来选择月份", 'info');
            }
            else {
                $.messager.confirm('操作提示', "确认删除标段【" + row.ContractName + "】下第" + month + "个月的工资吗？", function (r) {
                    if (r) {
                        $.post('/SectionSalary/Delete?projectID=' + projectID + '&contractType=' + encodeURI(contractType) + '&contractID=' + row.ContractID + '&year=' + year + '&month=' + month, function (res) {
                            if (res == "Success") {
                                initTable();
                                $.messager.alert('操作提示', '删除成功!', 'info');
                            }
                            else {
                                if (res == "") {
                                    $.messager.alert('操作提示', '删除失败!请查看该数据与其他模块下的信息的关联，或联系管理员。', 'info');
                                }
                                else {
                                    $.messager.alert('操作提示', res, 'info');
                                }
                            }
                        });
                    }
                });
            }
        }
    }

    function cancelPopWindow(handleState) {
        if (handleState == "0") {
            initTable();
        }
        colseMyWindow("#myWindow");
    }

    function CloseWindow(data) {
        colseMyWindow("#myWindow");
        initTable();
        $.EasyuiSlide(data);
    }
</script>

<div class="easyui-layout" fit="true">
    <input type="hidden" id="hMonth" name="Month" />
    <div data-options="region:'north'" style="height:35px;">
        <table style="margin-top: 5px">
            <tr>
                <td style="width: 95px; text-align: center">项目名称</td>
                <td>
                    <input id="ProjectID" name="ProjectID" class="easyui-combobox" style="width: 180px;" />
                </td>
                <td style="width: 95px; text-align: center">合同类型</td>
                <td>
                    <input id="ContractType" name="ContractType" class="easyui-combobox" style="width: 180px;" />
                </td>
                <td style="width: 95px; text-align: center">年</td>
                <td>
                    <input id="Year" name="Year" class="easyui-combobox" style="width: 180px;" />
                </td>
                <td>
                    <a href="#" id="btnSearch" class="easyui-linkbutton" data-options="plain:true" onclick="Search();">查看</a>
                </td>
            </tr>
        </table>
    </div>

    <div data-options="region:'center'">
        <div class="easyui-layout" fit="true">
            <div data-options="region:'north'" style="height: 150px;">
                <table id="summaryDataGrid" fit="true"></table>
                <div id="summaryToolBar">
                    @Html.Raw(ViewBag.ToolBarInfo)
                </div>
            </div>
            <div data-options="region:'center'">
                <div id="divRemark" style="display:none;">
                    <p>说明：每月末由承包人先在系统中填写农民工本月工资表，填写完毕后打印，然后将打印的工资表按人头逐一签字或按手印，最后将签字后的表格加盖承包人公章后扫描，以附件形式上传到系统中，再按流程逐级上报审批。如果上传的附件中的信息与系统填报的信息不一致，审核人员则直接退回，不予审批。本表必须包含当月所雇佣的所有农名工，不得遗漏，否则一切责任后果都由承包人承担。</p>
                </div>
                <table id="detailDataGrid" fit="true"></table>
            </div>
            <div data-options="region:'south'" style="height: 100px;">
                <table id="documentGrid" fit="true"></table>
            </div>
        </div>
    </div>
</div>
